#ifndef _MT5_TUTORIAL_H_
#define _MT5_TUTORIAL_H_


#include "mat_logicboard.h"

#include "ui/ui_sprite.h"
#include "math/counter.h"

namespace ui
{
	class UIWidget;
};

class MATTutorial : public MATAniFinishEventReceiveable
{
public:

	struct BoardInfo
	{
		BoardInfo();

		MATGem*								m_Content;
		int									m_X;
		int									m_Y;
	};

	struct TutorialMove
	{
		~TutorialMove();

		int												m_StartX;
		int												m_StartY;
		int												m_EndX;
		int												m_EndY;
		std::string										m_Text1;
		std::string										m_Text2;
		
		std::vector<BoardInfo*>							m_Smalls;									
				
	};
	
	struct TutorialData
	{
		~TutorialData();
		
		int												m_ActivateLevel;
		std::vector<TutorialMove*>						m_Moves;
		std::vector<BoardInfo*>							m_BoardStart;
		
	};


	enum	STATE
	{
		STATE_NONE,

		STATE_WAIING_TOACTIVATE,
		STATE_START,
		STATE_NOFINGER,
		STATE_FINGER_POINTSTART,
		//STATE_MOVE,
		STATE_FINGER_POINTEND,
		STATE_MOVEFINISH,
		STATE_PAUSE_BEFORE_NEXTMOVE,
		STATE_DELAY_END,
		STATE_CLEARED,

		STATE_C,

	};

	MATTutorial();
	~MATTutorial();
	

	
	bool												Start();
	void												Tick(float dt);
	void												Render(float Scale);
	virtual void										OnAnimationFinish(enum MATAnimation::ANI_TYPE AnimationType);
	void												AddSmallThree();
	bool												IsActive()const { return ( !IsFinish() &&  m_State != STATE_WAIING_TOACTIVATE); };
	bool												IsFinish() const { return m_State == STATE_CLEARED; };
	void												ForceFinish();

	void												MouseButtonDown(const math::Vec2& Pos, int Y, int X);
	void												MouseButtonReleased(const math::Vec2& Pos, int Y, int X);
	void												Load();
	void												StartImediately();
	
protected:

	
	void												Clear();

	void												NextState();

		
	std::vector<TutorialData*>							m_Tutorials;
	int													m_CurrentTutorial;
	int													m_CurrentStep;
	
	STATE												m_State;

	math::Vec2											m_PosFinger;
	math::Vec2											m_PosStart;
	math::Vec2											m_PosEnd;
	//math::Vec2										m_DirToTarget;
	//float												m_DistToTravel;	
	int													m_CurrentX;
	int													m_CurrentY;

	ui::UISprite										m_SpriteFinger;
	ui::UISprite										m_SpriteArrow;
	ui::UISprite										m_SpriteBlack;

	math::Vec2											m_SpriteFingerSize;
	math::Vec2											m_SpriteArrowSize;


	float												m_CounterToNextState;
	math::Counter										m_CounterArrow;
	float												m_StartDelay;
	ui::UIWidget*										m_pUIInstruction;
	bool												m_IsLoaded;
	float												m_AnotherClickDelay;

};

#endif